<template>
	<view class="login-container">
		<!-- 登录提示区域 -->
		<view class="login-info">
			<image class="login-logo" src="/static/logo.png"></image>
			<text class="login-text">登录了解更多优惠好物</text>
		</view>
		
		<!-- 快速登录按钮 -->
		<button class="login-btn" @click="quickLogin">同意协议并手机号快捷登录</button>
		
		<!-- 协议说明 -->
		<view class="agreement-info">
			<text class="check-icon">✓</text>
			<text class="agreement-text">
				若手机号未注册将进入注册流程，注册即为同意
				<text class="agreement-link" @click="openUserAgreement">《京东用户服务协议》</text>
				<text class="agreement-link" @click="openPrivacyPolicy">《京东隐私政策》</text>
			</text>
		</view>
		
		<!-- 其他登录方式 -->
		<view class="other-login">
			<text class="other-login-title">其他登录方式</text>
			<view class="other-login-methods">
				<view class="login-method" @click="phoneVerify">
					<image class="method-icon" src="/static/phone.png"></image>
					<text class="method-text">手机验证</text>
				</view>
				<view class="login-method" @click="accountLogin">
					<image class="method-icon" src="/static/account.png"></image>
					<text class="method-text">账户登录</text>
				</view>
			</view>
		</view>
		
		<!-- 手机验证码弹窗 -->
		<view class="verify-dialog" v-if="showVerifyDialog">
			<view class="dialog-content">
				<view class="dialog-header">
					<text class="dialog-close" @click="closeVerifyDialog">×</text>
					<view class="dialog-title-container">
						<image class="dialog-logo" src="/static/jd-logo.png"></image>
						<text class="dialog-title">京东购物 | 点外卖领国补 申请</text>
					</view>
				</view>
				<view class="dialog-body">
					<text class="phone-title">你的手机号码</text>
					<text class="phone-number">{{maskedPhoneNumber}}</text>
					<text class="verify-tip">微信绑定号码</text>
					<view class="btn-container">
						<button class="confirm-btn" @click="confirmVerify">允许</button>
						<button class="cancel-btn" @click="closeVerifyDialog">取消</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// 导入请求工具
	import { request } from '@/utils/request.js';
	
	export default {
		data() {
			return {
				phoneNumber: '18627868756',
				maskedPhoneNumber: '186****8756',
				showVerifyDialog: false,
				agreed: true
			}
		},
		methods: {
			// 快速登录
			quickLogin() {
				if (!this.agreed) {
					uni.showToast({
						title: '请同意用户协议和隐私政策',
						icon: 'none'
					});
					return;
				}
				
				// 显示验证弹窗
				this.showVerifyDialog = true;
			},
			
			// 确认验证
			confirmVerify() {
				// 调用登录接口
				request({
					url: '/api/user/login',
					method: 'POST',
					data: {
						phoneNumber: this.phoneNumber,
						type: 'quick'
					}
				}).then(res => {
					// 登录成功
					if (res.code === 0) {
						// 保存token
						uni.setStorageSync('token', res.data.token);
						
						// 提示登录成功
						uni.showToast({
							title: '登录成功',
							icon: 'success'
						});
						
						// 关闭验证弹窗
						this.showVerifyDialog = false;
						
						// 跳转到首页
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/index/index'
							});
						}, 1500);
					} else {
						uni.showToast({
							title: res.message || '登录失败',
							icon: 'none'
						});
					}
				}).catch(err => {
					uni.showToast({
						title: '网络错误，请稍后重试',
						icon: 'none'
					});
				});
			},
			
			// 关闭验证弹窗
			closeVerifyDialog() {
				this.showVerifyDialog = false;
			},
			
			// 手机验证
			phoneVerify() {
				uni.navigateTo({
					url: '/pages/login/phoneVerify'
				});
			},
			
			// 账户登录
			accountLogin() {
				uni.navigateTo({
					url: '/pages/login/accountLogin'
				});
			},
			
			// 打开用户协议
			openUserAgreement() {
				// 可以跳转到用户协议页面
				uni.navigateTo({
					url: '/pages/agreement/userAgreement'
				});
			},
			
			// 打开隐私政策
			openPrivacyPolicy() {
				// 可以跳转到隐私政策页面
				uni.navigateTo({
					url: '/pages/agreement/privacyPolicy'
				});
			}
		}
	}
</script>

<style>
	.login-container {
		padding: 50rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		background-color: #fff;
		height: 100vh;
	}
	
	.login-info {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-bottom: 80rpx;
		margin-top: 80rpx;
	}
	
	.login-logo {
		width: 120rpx;
		height: 120rpx;
		margin-bottom: 30rpx;
	}
	
	.login-text {
		font-size: 32rpx;
		color: #333;
	}
	
	.login-btn {
		width: 90%;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		background-color: #4CAF50;
		color: #fff;
		font-size: 32rpx;
		border-radius: 45rpx;
		margin-bottom: 30rpx;
	}
	
	.agreement-info {
		width: 90%;
		display: flex;
		align-items: flex-start;
		margin-bottom: 80rpx;
	}
	
	.check-icon {
		color: #E45A25;
		margin-right: 10rpx;
		font-size: 28rpx;
	}
	
	.agreement-text {
		color: #999;
		font-size: 24rpx;
		line-height: 1.5;
	}
	
	.agreement-link {
		color: #E45A25;
	}
	
	.other-login {
		width: 100%;
		margin-top: 100rpx;
	}
	
	.other-login-title {
		display: block;
		text-align: center;
		font-size: 28rpx;
		color: #999;
		position: relative;
		margin-bottom: 50rpx;
	}
	
	.other-login-title::before,
	.other-login-title::after {
		content: "";
		position: absolute;
		top: 50%;
		width: 30%;
		height: 1rpx;
		background-color: #eee;
	}
	
	.other-login-title::before {
		left: 0;
	}
	
	.other-login-title::after {
		right: 0;
	}
	
	.other-login-methods {
		display: flex;
		justify-content: center;
		margin-top: 30rpx;
	}
	
	.login-method {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin: 0 40rpx;
	}
	
	.method-icon {
		width: 80rpx;
		height: 80rpx;
		margin-bottom: 20rpx;
	}
	
	.method-text {
		font-size: 28rpx;
		color: #666;
	}
	
	/* 弹窗样式 */
	.verify-dialog {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 0.5);
		z-index: 999;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.dialog-content {
		width: 600rpx;
		background-color: #fff;
		border-radius: 8rpx;
		overflow: hidden;
	}
	
	.dialog-header {
		position: relative;
		padding: 30rpx;
	}
	
	.dialog-close {
		position: absolute;
		top: 20rpx;
		right: 20rpx;
		font-size: 40rpx;
		color: #666;
	}
	
	.dialog-title-container {
		display: flex;
		align-items: center;
	}
	
	.dialog-logo {
		width: 60rpx;
		height: 60rpx;
		margin-right: 10rpx;
	}
	
	.dialog-title {
		font-size: 28rpx;
		color: #333;
	}
	
	.dialog-body {
		padding: 30rpx;
	}
	
	.phone-title {
		font-size: 32rpx;
		color: #333;
		display: block;
		margin-bottom: 20rpx;
	}
	
	.phone-number {
		font-size: 36rpx;
		color: #333;
		font-weight: bold;
		display: block;
		margin-bottom: 20rpx;
	}
	
	.verify-tip {
		font-size: 28rpx;
		color: #999;
		display: block;
		margin-bottom: 30rpx;
	}
	
	.btn-container {
		display: flex;
		justify-content: space-between;
	}
	
	.confirm-btn {
		width: 48%;
		height: 80rpx;
		line-height: 80rpx;
		background-color: #4CAF50;
		color: #fff;
		font-size: 32rpx;
	}
	
	.cancel-btn {
		width: 48%;
		height: 80rpx;
		line-height: 80rpx;
		background-color: #f5f5f5;
		color: #333;
		font-size: 32rpx;
	}
</style> 